from sqlalchemy import *
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

import urldb
import urldb.model
from   urldb.model.url import  *

''' 
'''
class Populate(object):
    def __init__(self, options):
        self.db = None
        self.db = create_engine('sqlite:///url.db')
        self.db.echo = False
        metadata = MetaData(self.db)
        urldb.model.init(options)
        urldb.model.DeclarativeBase.metadata.drop_all(bind=self.db)
        urldb.model.DeclarativeBase.metadata.create_all(bind=self.db)

    def insert(self):
        table = Url.__table__
        i = table.insert()
        u_rec = {'name':'url_1'}
        self.db.execute(table.insert(), u_rec)
        id = 1
        stuff = [{'url_id':id, 'name':'n1', 'value':'v1'}, {'url_id':id, 'name':'n2', 'value':'v2'}]
        self.insertParamArray(stuff)

    def insertParamArray(self, recs):
        table = UrlParam.__table__
        i = table.insert()
        self.db.execute(table.insert(), recs)

